package cloud.maque.module.system.controller;

import cloud.maque.common.core.request.PageRequest;
import cloud.maque.common.core.response.R;
import cloud.maque.module.system.entity.SysDictItem;
import cloud.maque.module.system.service.DictItemService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典接口
 */
@Tag(name = "字典项接口")
@RestController
@RequestMapping(value = "/dict-item")
public class DictItemController {


    @Autowired
    DictItemService itemService;

    @Operation(summary = "字典项列表")
    @PostMapping("/list")
    public R<IPage<SysDictItem>> List(@RequestBody PageRequest<SysDictItem> pageReq) {
        return R.ok("OK", itemService.GetList(pageReq));
    }

    @Operation(summary = "有效的字典项列表")
    @GetMapping("/list-enable/{dictId}")
    public R<List<SysDictItem>> List(@PathVariable("dictId") String dictId) {
        return R.ok("OK", itemService.GetItemListEnabled(dictId));
    }

    @Operation(summary = "有效的字典项列表")
    @GetMapping("/list-enable-code/{dictCode}")
    public R<List<SysDictItem>> ListByCode(@PathVariable("dictCode") String dictCode) {
        return R.ok("OK", itemService.GetItemListEnabledByCode(dictCode));
    }

    @Operation(summary = "有效的字典项")
    @GetMapping("/one-enable/{dictId}/{itemValue}")
    public R<SysDictItem> GetOneEnable(@PathVariable("dictId") String dictId, @PathVariable("itemValue") String itemValue) {
        return R.ok("OK", itemService.GetItem(dictId, itemValue));
    }

    @Operation(summary = "获取的字典项")
    @GetMapping("/one/{dictId}/{itemValue}")
    public R<SysDictItem> GetOneItem(@PathVariable("dictId") String dictId, @PathVariable("itemValue") String itemValue) {
        return R.ok("OK", itemService.GetItem(dictId, itemValue));
    }

    @Operation(summary = "字典项保存")
    @PostMapping("/save")
    public R<SysDictItem> Save(@RequestBody SysDictItem data) {

        return R.ok("OK", itemService.SaveDictItme(data));
    }

    @Operation(summary = "字典项删除")
    @DeleteMapping("/delete/{id}")
    public R<Boolean> Delete(@PathVariable("id") String id) {
        return R.ok("OK", itemService.DeleteItme(id));
    }
}
